<?php
/**
 *后台约车记录控制器
 */

namespace Admin\Controller;

class MeetingCarRecordController extends ComController
{

    //后台驾校约车记录列表
    public  function  index(){

        //获取登录者的id--即驾校id
        $SchooId = session('uid');
        //搜索
        $p= intval($_GET['p'])?$_GET['p']:1;
        $MeetingCarRecord = M('MeetingCarRecord');
        $pagesize = 15;#每页数量
        $offset = $pagesize * ($p - 1);//计算记录偏移量
        $prefix = C('DB_PREFIX');

         $where = 'mcr.school_id ='. $SchooId;



        $title='预约记录报表';

        //教练名
        $CoachName = isset($_GET['coach_name']) ? htmlentities($_GET['coach_name']) : '';

        if ($CoachName) {
            $where .= "  and  mcr.coach_name like '%{$CoachName}%' ";
        }


        $count= $MeetingCarRecord->join('as mcr left join  driving_appointment_time  as at    on mcr.time_id=at.id')
                                 ->field('mcr.id, mcr.user_name,mcr.user_phone, mcr.coach_name,mcr.coach_head, mcr.day, mcr.study_hours, mcr.category, mcr.course, mcr.status,mcr.add_time,mcr.coach_phone,mcr.site,mcr.car_num,mcr.type,mcr.ispay,mcr.price, at.time')
                                 ->where($where)
                                 ->order('mcr.id asc' )
                                 ->count();

       $data= $MeetingCarRecord->join('as mcr left join  driving_appointment_time  as at    on mcr.time_id=at.id')
                               ->field('mcr.id, mcr.user_name,mcr.user_phone, mcr.coach_name,mcr.coach_head, mcr.day,  mcr.category, mcr.course, mcr.status,mcr.add_time,mcr.coach_phone,mcr.site,mcr.car_num,mcr.type,mcr.ispay,mcr.price,at.time,at.time as study_hours')
                               ->where($where)
                               ->order('mcr.id asc' )
                               ->limit($offset . ',' . $pagesize)
                               ->select();

        foreach($data as $k => $v){
            $arr = explode('-',$v['study_hours']);
            $time = round((strtotime($arr[1]) - strtotime($arr[0])) / 3600 );
            $data[$k]['study_hours'] = $time;
        }


        session('data',$data);
        session('title',$title);

//
//        dump($data);
//        dump($MeetingCarRecord->getLastSql());
//        exit;


        $page = new \Think\Page($count, $pagesize);
        $page = $page->show();

        $this->assign('data', $data);
        $this->assign('page', $page);
        $this->display();


    }



    //打印
    public function dayin(){
        $data = session('data');
        $title = session('title');
        $this->assign('data',$data);
        $this->assign('title',$title);
        $this->display();
    }











}